package com.maybach.workflow.core.processor.impl;


import com.maybach.workflow.common.api.WorkFlowContext;
import com.maybach.workflow.common.api.node.BaseNode;
import com.maybach.workflow.common.api.node.TransactionNode;
import com.maybach.workflow.core.expression.IExpression;
import com.maybach.workflow.core.expression.JuelExpression;
import com.maybach.workflow.core.expression.LogicalExprHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by houenxun on 15/8/14.
 */
public class TransactionProcessor extends AbstractProcessor{
    protected IExpression expression = new JuelExpression();



    @Autowired
    protected LogicalExprHelper logicalExprHelper;

    @Override
    public List<BaseNode> getNextNodes(WorkFlowContext workFlowContext) {
        TransactionNode transactionNode = (TransactionNode)workFlowContext.getThisNode();
        if(logicalExprHelper.judgeFairily(transactionNode.getExpression(), workFlowContext.getBizData())){
            return getCommonNextNodes(workFlowContext);
        }
        return new ArrayList<BaseNode>();
    }

    @Override
    public boolean runIn(WorkFlowContext workFlowContext) {
        TransactionNode transactionNode = (TransactionNode)workFlowContext.getThisNode();
        if(logicalExprHelper.judgeFairily(transactionNode.getExpression(), workFlowContext.getBizData())){
            this.runOut(workFlowContext);
            return true;
        }
        return false;
    }

    @Override
    public void runOut(WorkFlowContext workFlowContext) {
        super.noPersistRunOut(workFlowContext);
    }
}
